import {isString, isArray, generateElement} from "../functions/common.js";

export class MyUI {
    constructor(){
        this.elem = null;
    }
    getElement() {
        return this.elem;
    }
}

export class Detail extends MyUI{
    constructor(title, textList, config){
        super();
        this.elem = generateElement({
            type: "div",
            ...config
        });
        this.elem.appendChild(generateElement({
            type: "h1",
            margin: "10px 0",
            innerText: title,
        }));
        if (textList && textList instanceof Array){
            for (let i = 0;i<textList.length; i++){
                this.elem.appendChild(generateElement({
                    type: "p",
                    margin: "4px 0",
                    innerText: textList[i],
                }))
            }
        }
    }
}

export class MyDetail extends MyUI{
    constructor(title, sentences){
        super();
        if (isString(title) && isArray(sentences)){
            this.elem = generateElement({
                type: "fieldset",
                className: "layui-elem-field",
                margin: "10px 0",
            });
            let legend = generateElement({
                type: "legend",
                fontSize: "26px",
                innerText: title,
            });
            this.elem.appendChild(legend);
            this.containerDiv = generateElement({
                type: "div",
                className: "layui-field-box",
            });
            this.elem.appendChild(this.containerDiv);
            // generate sentences;
            for (let i = 0;i<sentences.length;i++){
                this.containerDiv.appendChild(generateElement({
                    type: "p",
                    margin: "5px 10px",
                    innerText: sentences[i],
                }))
            }
        }
    }
}